﻿using Roslyn.Compilers.CSharp;

namespace InterfaceWeaver.CustomTool
{
    public class ParsedCodeContext
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ParsedCodeContext" /> class.
        /// </summary>
        /// <param name="parsedCode">The parsed code.</param>
        public ParsedCodeContext(CompilationUnitSyntax parsedCode)
        {
            this.ParsedCode = parsedCode;
        }

        /// <summary>
        /// Gets the parsed code.
        /// </summary>
        public CompilationUnitSyntax ParsedCode { get; private set; }

        /// <summary>
        /// Gets or sets the current namespace syntax.
        /// </summary>
        public NamespaceDeclarationSyntax CurrentNamespaceSyntax { get; private set; }

        /// <summary>
        /// Gets or sets the current interface syntax.
        /// </summary>
        public InterfaceDeclarationSyntax CurrentInterfaceSyntax { get; private set; }

        /// <summary>
        /// Gets or sets the current member synatx.
        /// </summary>
        public MemberDeclarationSyntax CurrentMemberSyntax { get; private set; }

        /// <summary>
        /// Changes the context.
        /// </summary>
        /// <param name="currentNamespaceSyntax">The current namespace syntax.</param>
        public void ChangeContext(NamespaceDeclarationSyntax currentNamespaceSyntax)
        {
            this.CurrentNamespaceSyntax = currentNamespaceSyntax;
            this.CurrentInterfaceSyntax = null;
            this.CurrentMemberSyntax = null;
        }

        /// <summary>
        /// Changes the context.
        /// </summary>
        /// <param name="currentInterfaceSyntax">The current interface syntax.</param>
        public void ChangeContext(InterfaceDeclarationSyntax currentInterfaceSyntax)
        {
            this.CurrentInterfaceSyntax = currentInterfaceSyntax;
            this.CurrentMemberSyntax = null;
        }

        /// <summary>
        /// Changes the context.
        /// </summary>
        /// <param name="currentMemberSyntax">The current member syntax.</param>
        public void ChangeContext(PropertyDeclarationSyntax currentMemberSyntax)
        {
            this.CurrentMemberSyntax = currentMemberSyntax;
        }

        /// <summary>
        /// Changes the context.
        /// </summary>
        /// <param name="currentMemberSyntax">The current member syntax.</param>
        public void ChangeContext(EventDeclarationSyntax currentMemberSyntax)
        {
            this.CurrentMemberSyntax = currentMemberSyntax;
        }
    }
}
